Page({
  data: {
    laoren:"",
    openid: "",
    name: "",
    phone: "",
    id: "",
    sfz: "", //身份证号
  },
  onLoad() {
    // 导航栏
    // 1.获取屏幕可使用宽度
    let windowWidth = wx.getSystemInfoSync().windowWidth;
    // 2.获取状态栏高度
    const statusBarHeight = wx.getSystemInfoSync().statusBarHeight;
    //3.获取胶囊按钮位置信息
    const menuButton = wx.getMenuButtonBoundingClientRect();
    this.setData({
      navtop: menuButton.top,
      openid: getApp().globalData.openid
    })
    const that = this
    const app = getApp()
    this.setData({
      openid: app.globalData.openid
    })
    wx.request({
      url: 'https://dj.ifankui.com/api/usrEn/getProfile',
      method: "POST",
      data: {
        openid: this.data.openid
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: (res) => {
        console.log(res);
        console.log(res.data.data.jhr, );
        this.setData({
          name: res.data.data.realname,
          phone: res.data.data.mobile,
          id: res.data.data.id,
          laoren: res.data.data.laoren,
          sfz: res.data.data.sfz,
        }, () => {
          this.data.laoren.forEach(pp => {
            let birthYear = parseInt(pp.sfz.substring(6, 10));
            let birthMonth = parseInt(pp.sfz.substring(10, 12));
            let birthDay = parseInt(pp.sfz.substring(12, 14));
            // 获取当前日期
            let today = new Date();
            let currentYear = today.getFullYear();
            let currentMonth = today.getMonth() + 1;
            let currentDay = today.getDate();
            // 计算年龄
            let birthDate = new Date(birthYear, birthMonth - 1, birthDay);
            let age = currentYear - birthYear;
            // 调整年龄，如果当前月份和日期还没到生日，则减一岁
            if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
              age--;
            }
            that.setData({
              ['laoren[' + this.data.laoren.indexOf(pp) + '].age']: age
            },()=>{console.log(this.data.laoren);})
            
          });

        })
        // 提取出生年月日

      }
    })
  },
  gitfor() {
    wx.navigateBack({
      delta: -1
    })
  },
  callphone: function (e) {
    console.log(e.currentTarget.dataset.phone);
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.phone, // 这里填写要拨打的电话号码
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },
  bangding2(){
    wx.navigateTo({
      url: '../user/user',
    })
  },
})